<?php
/* ========== ########## ========== ########## ========== ########## ========== */
/*                                                                              */
/*   WHMCS v4.1.2 NULLED R4 by FLIPMODE  [ BAD SYNTAX ]                         */
/*                                                                              */
/*                             INTERNAL BAD SYNTAX NULLED VERSION: 2.5.9.6 R4   */
/*                                                                              */
/*   ALL files have been analysed, cleaned and nulled of:                       */
/*     - Call Backs  (100%)                                                     */
/*     - Link Backs (95%)                                                       */
/*     - Licensing  (100%)                                                      */
/*     - Remote Links + URL's                                                   */
/*                                                                              */
/*   WHMCS v4.1.2 RELEASED: 4th November 2009                                   */
/*    -> FIRST v4.1.2 NULL R1: 19th November 2009                               */
/*    -> UPDATED v4.1.2 NULL R4: 27th November 2009                             */
/*                                                                              */
/*   TESTING + VERIFICATION::                                                   */
/*     Files Cleaned, Nulled, Checked, Verified By:                             */
/*      -> FLIPMODE!                                                            */
/*     Decoded By:                                                              */
/*      -> FLIPMODE! + Unknown Decoder                                          */
/*     Tested By:                                                               */
/*      -> FLIPMODE!, LeetWolf, and 12 Anonymous Users...                       */
/*     WHMCS 4.1.2 Supplied By:                                                 */
/*      -> WHM CompleteShit Coder @ WHMCS.com                                   */
/*                                                                              */
/*                                                                              */
/*   IMPORTANT NOTE::                                                           */
/*   PLEASE NOTE THIS IS FOR TRIAL PURPOSES ONLY!                               */
/*                          LIKE IT? THEN BUY IT!                               */
/*                                                                              */
/* ========== ########## ========== ########## ========== ########## ========== */

function getcartconfigoptions ($pid, $values, $cycle, $accountid = '')
{
	global $CONFIG;
	global $_LANG;
	global $currency;
	if ($cycle == 'onetime')
	{
		$cycle = 'monthly';
	}

	$configoptions = array ();
	$cycle = strtolower (str_replace ('-', '', $cycle));
	if ($cycle == 'one time')
	{
		$cycle = 'monthly';
	}

	if ($accountid)
	{
		$values = array ();
		$result = select_query ('tblhostingconfigoptions', '', array ('relid' => $accountid));
		while ($data = mysql_fetch_array ($result))
		{
			$configid = $data['configid'];
			$result2 = select_query ('tblproductconfigoptions', '', array ('id' => $configid));
			$data2 = mysql_fetch_array ($result2);
			$optiontype = $data2['optiontype'];
			if (($optiontype == 3 OR $optiontype == 4))
			{
				$configoptionvalue = $data['qty'];
			}
			else
			{
				$configoptionvalue = $data['optionid'];
			}

			$values[$configid] = $configoptionvalue;
		}
	}

	$where = array ('pid' => $pid);
	if (!$_SESSION['adminid'])
	{
		$where['hidden'] = 0;
	}

	$result2 = select_query ('tblproductconfigoptions', '', $where, 'order` ASC,`id', 'ASC', '', 'tblproductconfiglinks ON tblproductconfiglinks.gid=tblproductconfigoptions.gid');
	while ($data2 = mysql_fetch_array ($result2))
	{
		$optionid = $data2['id'];
		$optionname = $data2['optionname'];
		$optiontype = $data2['optiontype'];
		if (strpos ($optionname, '|'))
		{
			$optionname = explode ('|', $optionname);
			$optionname = trim ($optionname[1]);
		}

		$options = array ();
		$selectedqty = 0;
		$selvalue = $values['' . $optionid];
		if ($optiontype == '3')
		{
			$result3 = select_query ('tblproductconfigoptionssub', '', array ('configid' => $optionid));
			$data3 = mysql_fetch_array ($result3);
			$opid = $data3['id'];
			$opname = $data3['optionname'];
			if (strpos ($opname, '|'))
			{
				$opname = explode ('|', $opname);
				$opname = trim ($opname[1]);
			}

			$opnameonly = $opname;
			$result4 = select_query ('tblpricing', '', array ('type' => 'configoptions', 'currency' => $currency['id'], 'relid' => $opid));
			$data = mysql_fetch_array ($result4);
			$setup = $data[substr ($cycle, 0, 1) . 'setupfee'];
			$price = $data[$cycle];
			if (0 < $price)
			{
				$opname .= ' ' . formatcurrency ($price);
			}

			$setupvalue = '';
			if (0 < $setup)
			{
				$setupvalue = ' + ' . formatcurrency ($setup) . ' ' . $_LANG['ordersetupfee'];
			}

			$options[] = array ('id' => $opid, 'name' => $opname . $setupvalue, 'nameonly' => $opnameonly, 'recurring' => $price);
			if (!$selvalue)
			{
				$selvalue = 0;
			}

			$selectedoption = $selsetup = $selrecurring = '';
			$selectedqty = $selvalue;
			$selvalue = $opid;
			if ($selectedqty)
			{
				$selname = $opnameonly;
				$selectedoption = $opname;
				$selsetup = $setup;
				$selrecurring = $price;
			}
		}
		else
		{
			if ($optiontype == '4')
			{
				$result3 = select_query ('tblproductconfigoptionssub', '', array ('configid' => $optionid));
				$data3 = mysql_fetch_array ($result3);
				$opid = $data3['id'];
				$opname = $data3['optionname'];
				if (strpos ($opname, '|'))
				{
					$opname = explode ('|', $opname);
					$opname = trim ($opname[1]);
				}

				$opnameonly = $opname;
				$result4 = select_query ('tblpricing', '', array ('type' => 'configoptions', 'currency' => $currency['id'], 'relid' => $opid));
				$data = mysql_fetch_array ($result4);
				$setup = $data[substr ($cycle, 0, 1) . 'setupfee'];
				$price = $data[$cycle];
				if (0 < $price)
				{
					$opname .= ' ' . formatcurrency ($price);
				}

				$setupvalue = '';
				if (0 < $setup)
				{
					$setupvalue = ' + ' . formatcurrency ($setup) . ' ' . $_LANG['ordersetupfee'];
				}

				$options[] = array ('id' => $opid, 'name' => $opname . $setupvalue, 'nameonly' => $opnameonly, 'recurring' => $price);
				if (!is_numeric ($selvalue))
				{
					$selvalue = 0;
				}

				$selectedqty = $selvalue;
				$selvalue = $opid;
				$selname = $opnameonly;
				$selectedoption = $opname;
				$selsetup = $setup * $selectedqty;
				$selrecurring = $price * $selectedqty;
			}
			else
			{
				$result3 = select_query ('tblproductconfigoptionssub', '', array ('configid' => $optionid), 'sortorder` ASC,`id', 'ASC');
				while ($data3 = mysql_fetch_array ($result3))
				{
					$opid = $data3['id'];
					$opname = $data3['optionname'];
					$hidden = $data3['hidden'];
					if (strpos ($opname, '|'))
					{
						$opname = explode ('|', $opname);
						$opname = trim ($opname[1]);
					}

					$opnameonly = $opname;
					$result4 = select_query ('tblpricing', '', array ('type' => 'configoptions', 'currency' => $currency['id'], 'relid' => $opid));
					$data = mysql_fetch_array ($result4);
					$setup = $data[substr ($cycle, 0, 1) . 'setupfee'];
					$price = $data[$cycle];
					if (0 < $price)
					{
						$opname .= ' ' . formatcurrency ($price);
					}

					$setupvalue = '';
					if (0 < $setup)
					{
						$setupvalue = ' + ' . formatcurrency ($setup) . ' ' . $_LANG['ordersetupfee'];
					}

					if (($_SESSION['adminid'] OR !$hidden))
					{
						$options[] = array ('id' => $opid, 'name' => $opname . $setupvalue, 'nameonly' => $opnameonly, 'recurring' => $price);
					}

					if (($opid == $selvalue OR !$selvalue))
					{
						$selname = $opnameonly;
						$selectedoption = $opname;
						$selsetup = $setup;
						$selrecurring = $price;
						$selvalue = $opid;
						continue;
					}
				}
			}
		}

		$configoptions[] = array ('id' => $optionid, 'optionname' => $optionname, 'optiontype' => $optiontype, 'selectedvalue' => $selvalue, 'selectedqty' => $selectedqty, 'selectedname' => $selname, 'selectedoption' => $selectedoption, 'selectedsetup' => $selsetup, 'selectedrecurring' => $selrecurring, 'options' => $options);
	}

	return $configoptions;
}

?>